cmake_minimum_required(VERSION 3.10 FATAL_ERROR)

# project name and language
project(example LANGUAGES CXX)

# require C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# read PROGRAM_VERSION from file
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION.txt")
  file(READ "${CMAKE_CURRENT_SOURCE_DIR}/VERSION.txt" PROGRAM_VERSION)
  string(STRIP "${PROGRAM_VERSION}" PROGRAM_VERSION)
else()
  message(FATAL_ERROR "File ${CMAKE_CURRENT_SOURCE_DIR}/VERSION.txt not found")
endif()

# generate file version.hpp based on version.hpp.in
configure_file(
  version.hpp.in
  generated/version.hpp
  @ONLY
)

# example code
add_executable(example example.cpp)

# needs to find the generated header file
target_include_directories(example
  PRIVATE
    ${CMAKE_CURRENT_BINARY_DIR}/generated
)